#ifndef _IMG_UPDATE_
#define _IMG_UPDATE_

#include "hisi6421.h"

#define CRC_CHECK_ENABLE
#define VERSION_CHECK_ENABLE

#define GSM_CPL_LENGTH                            5248

#define LOWEST_VOLT_VALUE                         3968

/*update file name*/
#define SD_UPDATE_FILE_NAME                       "k3img.bin"

// max file type in k3img.bin
#define MAX_DOWNLOAD_FILE_TYPE                    10

/*phy memory address to restore FAT buffer*/
#define FAT_BUFFER_PHY_ADDRESS                    (MEM_BUF_END)

#define FAT_BUFFER_LENGTH                         0x100000

#define CP_IMAGE_BUFFER_LENGTH                    0x1000000

// phy memory address to restore CP image
#define CP_IMAGE_BUFFER_PHY_ADDRESS               (FAT_BUFFER_PHY_ADDRESS + FAT_BUFFER_LENGTH)

//select key value
#define VK_LEFT_SOFT                              0x2
#define VK_RIGHT_SOFT                             0x12
#define VOL_UP                                    0x11
#define VOL_DOWN                                  0x9

/*key defination*/
#define UPDATE_SELECT_YES_KEY                     VK_LEFT_SOFT
#define UPDATE_SELECT_NO_KEY                      VK_RIGHT_SOFT
#define RESET_YES_KEY                             VK_RIGHT_SOFT

#define SDUPDATE_SELECTKEY_1                      VOL_UP
#define SDUPDATE_SELECTKEY_2                      VOL_DOWN

//wait time for select
#define WAIT_TIME_FOR_DELAY                       200000
#define MAX_WAIT_COUNT_FOR_UPDATE                 (20*WAIT_TIME_FOR_DELAY)
#define MAX_WAIT_COUNT_FOR_RESET                  (5*WAIT_TIME_FOR_DELAY)

#define WAIT_TIME_SHOW_INFO                       1000

//color defination :: RGB
#define R888_R565(R)                              ((R) >> 3)
#define G888_G565(G)                              ((((G) >> 5) << 3)|((G) & 0x7))
#define B888_B565(B)                              ((B) >> 3)
#define RGB888_RGB565(R,G,B)                      ((R888_R565(R) << 11)|(G888_G565(G)<<5)|B888_B565(B))

#define PROGRESSBAR_BACKGROUND_COLOR              RGB888_RGB565(255, 255, 255)
#define SELECT_BACKGROUND_COLOR                   RGB888_RGB565(16, 130, 16)
#define SELECT_FONT_COLOR                         RGB888_RGB565(255, 255, 255)
#define BACKGROUND_COLOR                          RGB888_RGB565(214, 239, 214)
#define BACKGROUND_FONT_COLOR                     0

//max length for 1 line
#define MAX_PRINTF_SIZE                           50

//MDM function return value
#define ERR_NOERROR                               1

/*lcd print position*/
#if defined LCD_QVGA

#if defined APP_LANDSCAPE

#define LCD_MAX_RIGHT_VALUE                       320
#define LCD_MAX_BOTTOM_VALUE                      240

#define FONT_HIGH_SIZE                            20

#define SPACE_BETWEEN_FONT                        5

#define SELECT_MSG_LEFT_POS_LEFT                  35
#define SELECT_MSG_LEFT_POS_RIGHT                 65
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 265
#define SELECT_MSG_RIGHT_POS_RIGHT                295
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          50
#define TIP_MSG_POS_RIGHT                         270

#define TIP1_MSG_POS_TOP                          30
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        30
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        60
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        160
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  60
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       80
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#else
#define LCD_MAX_RIGHT_VALUE                       240
#define LCD_MAX_BOTTOM_VALUE                      320

#define FONT_HIGH_SIZE                            20

#define SPACE_BETWEEN_FONT                        5

#define SELECT_MSG_LEFT_POS_LEFT                  35
#define SELECT_MSG_LEFT_POS_RIGHT                 65
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 185
#define SELECT_MSG_RIGHT_POS_RIGHT                215
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          10
#define TIP_MSG_POS_RIGHT                         230

#define TIP1_MSG_POS_TOP                          30
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        30
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        60
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        160
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  60
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       80
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)

#endif
#elif defined LCD_WQVGA

#if defined APP_LANDSCAPE
#define LCD_MAX_RIGHT_VALUE                       400
#define LCD_MAX_BOTTOM_VALUE                      240

#define FONT_HIGH_SIZE                            20

#define SPACE_BETWEEN_FONT                        5

#define SELECT_MSG_LEFT_POS_LEFT                  35
#define SELECT_MSG_LEFT_POS_RIGHT                 65
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 345
#define SELECT_MSG_RIGHT_POS_RIGHT                375
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          90
#define TIP_MSG_POS_RIGHT                         310

#define TIP1_MSG_POS_TOP                          30
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        30
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        60
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        160
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  60
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       80
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#else
#define LCD_MAX_RIGHT_VALUE                       240
#define LCD_MAX_BOTTOM_VALUE                      400

#define FONT_HIGH_SIZE                            20

#define SPACE_BETWEEN_FONT                        5

#define SELECT_MSG_LEFT_POS_LEFT                  35
#define SELECT_MSG_LEFT_POS_RIGHT                 65
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 185
#define SELECT_MSG_RIGHT_POS_RIGHT                215
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          10
#define TIP_MSG_POS_RIGHT                         230

#define TIP1_MSG_POS_TOP                          30
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        30
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        60
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        160
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  60
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       80
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#endif

#elif defined LCD_VGA

#if defined APP_LANDSCAPE
#define LCD_MAX_RIGHT_VALUE                       640
#define LCD_MAX_BOTTOM_VALUE                      480

#define FONT_HIGH_SIZE                            40

#define SPACE_BETWEEN_FONT                        10

#define SELECT_MSG_LEFT_POS_LEFT                  70
#define SELECT_MSG_LEFT_POS_RIGHT                 130
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 530
#define SELECT_MSG_RIGHT_POS_RIGHT                590
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          100
#define TIP_MSG_POS_RIGHT                         540

#define TIP1_MSG_POS_TOP                          60
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        60
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        120
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        320
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  120
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       160
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#else
#define LCD_MAX_RIGHT_VALUE                       480
#define LCD_MAX_BOTTOM_VALUE                      640

#define FONT_HIGH_SIZE                            40

#define SPACE_BETWEEN_FONT                        10

#define SELECT_MSG_LEFT_POS_LEFT                  70
#define SELECT_MSG_LEFT_POS_RIGHT                 130
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 370
#define SELECT_MSG_RIGHT_POS_RIGHT                430
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          20
#define TIP_MSG_POS_RIGHT                         460

#define TIP1_MSG_POS_TOP                          60
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        60
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        120
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        320
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  120
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       160
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#endif

#elif defined LCD_WVGA

#if defined APP_LANDSCAPE
#define LCD_MAX_RIGHT_VALUE                       800
#define LCD_MAX_BOTTOM_VALUE                      480

#define FONT_HIGH_SIZE                            40

#define SPACE_BETWEEN_FONT                        10

#define SELECT_MSG_LEFT_POS_LEFT                  70
#define SELECT_MSG_LEFT_POS_RIGHT                 130
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 690
#define SELECT_MSG_RIGHT_POS_RIGHT                750
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          180
#define TIP_MSG_POS_RIGHT                         620

#define TIP1_MSG_POS_TOP                          60
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        60
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        120
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        320
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  120
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       160
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#else
#define LCD_MAX_RIGHT_VALUE                       480
#define LCD_MAX_BOTTOM_VALUE                      800

#define FONT_HIGH_SIZE                            40

#define SPACE_BETWEEN_FONT                        10

#define SELECT_MSG_LEFT_POS_LEFT                  70
#define SELECT_MSG_LEFT_POS_RIGHT                 130
#define SELECT_MSG_LEFT_POS_TOP                   (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_LEFT_POS_BOTTOM                (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define SELECT_MSG_RIGHT_POS_LEFT                 370
#define SELECT_MSG_RIGHT_POS_RIGHT                430
#define SELECT_MSG_RIGHT_POS_TOP                  (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT - FONT_HIGH_SIZE)
#define SELECT_MSG_RIGHT_POS_BOTTOM               (LCD_MAX_BOTTOM_VALUE - SPACE_BETWEEN_FONT)

#define TIP_MSG_POS_LEFT                          10
#define TIP_MSG_POS_RIGHT                         470

#define TIP1_MSG_POS_TOP                          60
#define TIP1_MSG_POS_BOTTOM                       (TIP1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR1_MSG_POS_TOP                        60
#define ERROR1_MSG_POS_BOTTOM                     (ERROR1_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR2_MSG_POS_TOP                        120
#define ERROR2_MSG_POS_BOTTOM                     (ERROR2_MSG_POS_TOP + FONT_HIGH_SIZE)

#define ERROR3_MSG_POS_TOP                        320
#define ERROR3_MSG_POS_BOTTOM                     (ERROR3_MSG_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_INFO_POS_TOP                  120
#define PROGRESSBAR_INFO_POS_BOTTOM               (PROGRESSBAR_INFO_POS_TOP + FONT_HIGH_SIZE)

#define PROGRESSBAR_POS_TOP                       160
#define PROGRESSBAR_POS_BOTTOM                    (PROGRESSBAR_POS_TOP + FONT_HIGH_SIZE)
#endif

#endif

//FLASH operate directory:
//1          - normal order
//0xFFFFFFFF - reverse order
#define FLASH_BLOCK_NORMAL_SEQ                    1
#define FLASH_BLOCK_BACKWORD_SEQ                  (0xFFFFFFFF)

void SdUpdateMain(void);

#endif
